limsResult.abnormalDetailPage = {

    getBtnToolbar : function(){
        let _this = this;
        return {
            type: 'btnToolbar',
            items: [{
                type: 'button',
                text: 'GIKAM.BUTTON.BACK',
                icon: 'back',
                onClick: function () {
                    if (_this.param.modal) {
                        Gikam.getLastModal().close()
                    } else {
                        workspace.window.goBack()
                    }
                }
            }, {
                type: 'button',
                text: 'LIMS.T_LIMS_ORDER_TASK.BUTTON.CONTINUE',
                icon: 'submit', color: 'success',
                onClick: function () {
                    let grid = Gikam.getComp('abnormal-task-list-grid');
                    if (Gikam.isEmpty(_this.param.ids)) {
                        Gikam.alert('GIKAM.TIP.CHOOSE_ONE_ITEM');
                        return;
                    }
                    Gikam.confirm('GIKAM.MODAL.SUBMIT', 'GIKAM.TIP.SUBMIT', function () {
                        workspace.window.showMask();
                        Gikam.postText(limsResult.runUrl + '/action/abnormal/pass',
                            Gikam.getJsonWrapper(null, [null, [{id : _this.param.ids, parallelId : _this.param.parallelId}]])).done(function () {

                        }).always(function () {
                            workspace.window.closeMask();
                            workspace.window.goBack().done(function () {
                                grid.refresh();
                            });
                        });
                    })
                }
            },{
                type: 'button',
                text: 'LIMS.T_LIMS_ORDER_TASK.BUTTON.STOP',
                icon: 'reject',
                onClick: function () {
                    let grid = Gikam.getComp('abnormal-task-list-grid');
                    if (Gikam.isEmpty(_this.param.ids)) {
                        Gikam.alert('GIKAM.TIP.CHOOSE_ONE_ITEM');
                        return;
                    }
                    Gikam.createLimsModal({
                        title: 'LIMS.T_LIMS_ORDER_TASK.BUTTON.STOP',
                        height: 220,
                        width: 380,
                        onConfirm: function () {
                            var form = Gikam.getComp('confirm-form');
                            if (form.validate()) {
                                let data = form.getData();
                                workspace.window.showMask();
                                Gikam.postText(limsResult.runUrl + '/action/abnormal/stop',
                                    Gikam.getJsonWrapper(data, [null,[{id : _this.param.ids,parallelId : _this.param.parallelId}] ])).done(function () {

                                }).always(function () {
                                    Gikam.getLastModal().close();
                                    workspace.window.closeMask();
                                    workspace.window.goBack().done(function () {
                                        grid.refresh();
                                    });
                                });
                            }
                        },
                        m: {
                            type: 'form',
                            id: 'confirm-form',
                            fields: [{
                                field: 'reason',
                                title: 'T_CORE_EMAIL_TEMPLATE.REMARK',
                                validators: ['notEmpty'],
                                type: 'textarea',
                                height: 100,
                            }],
                            columns: 1,
                        }
                    })
                }
            }]
        }
    },

    getRunOrderTaskTab : function(){
        let _this = this;
        return {
            type: 'tab',
            panels: [{
                title: 'T_CORE_ITEM.SERVICE_NAME',
                items: [{
                    type: 'grid',
                    id: 'abnormal-analyte-grid',
                    page: false,
                    url: limsResult.baseUrl + '/queries',
                    requestData: {
                        orderTaskId_EQ: _this.param.ids
                    },
                    columns: limsResult.getResultListColumns(),
                }]
            }, {
                title: 'MODULE.BUSINESS.RESULT.TAB.DERIVATIVE',
                items: [{
                    type: 'grid',
                    id: 'result-abnormal-derivative-grid',
                    url: Gikam.printf(limsResult.derivativelUrl + '/tasks/{taskId}/queries', {
                        taskId: _this.param.ids
                    }),
                    columns: limsResult.getAllDerivativeEditListColumns(),
                }]
            }, {
                title: 'GIKAM.FILE.ATTACHMENT',
                items: [{
                    type: 'uploader',
                    id: 'result-abnormal-uploader',
                    filter: false,
                    readonly: true,
                    dbTable: 'T_LIMS_RUN',
                    bizId: _this.param.runCode,
                    formatterGridColumns: function (columns) {
                        columns.splice(2, 0, {
                            field: 'bizCategory',
                            title: 'LIMS.MODLE.FILE.FILETYPE',
                            type: 'select',
                            width: 140,
                            category: 'sys',
                            param: {
                                codeCategoryId: 'fjType'
                            }
                        });
                        return Gikam.getFormatterGridColumns(columns, true);
                    }
                }]
            }, {
                title: 'T_CORE_FILE.OPERATE.OPERATION.RECORD',
                items: [{
                    type: 'grid',
                    id: 'abnormal-task-list-grid-audit-record',
                    columns: limsResult.getFlowListColumns(),
                    url: limsResult.auditRecordUrl + '/queries',
                    requestData: {
                        businessId_SEQ: _this.param.ids,
                        businessCode_SEQ: 'T_LIMS_ORDER_TASK'
                    }
                }]
            }]
        }
    },

    create : function(){
        let _this = this;
        let render = workspace.window.$dom;
        if (_this.param.modal) {
            render = Gikam.getLastModal().window.$dom;
        }
        Gikam.create('layout', {
            center: {
                items: [this.getBtnToolbar(), _this.getRunOrderTaskTab()]
            },
            renderTo: render
        });
    },

    init : function (param) {
        this.param = param;
        this.create();
    }

};